﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Z13qu.Model;

namespace Log.Core
{
    public class LogHelper
    {
        public static void SetConfig()
        {
            log4net.Config.XmlConfigurator.Configure();
        }

        public static void SetConfig(string filePath)
        {
            FileInfo configFile = new FileInfo(filePath);
            log4net.Config.XmlConfigurator.ConfigureAndWatch(configFile);
        }

        public static void SetConfig(FileInfo configFile)
        {
            log4net.Config.XmlConfigurator.ConfigureAndWatch(configFile);
        }


        private static readonly log4net.ILog log = log4net.LogManager.GetLogger("FileLog");

        //(高) OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL (低)

        /// <summary>
        /// 普通日志信息
        /// </summary>
        /// <param name="message"></param>
        public static void Info(Sys_Log syslog)
        {
            syslog.Level = LogLevel.INFO.ToString();
            if (log.IsInfoEnabled)
            {
                log.Info(syslog);
            }
        }

        /// <summary>
        /// 调试日志信息
        /// </summary>
        /// <param name="message"></param>
        public static void Debug(Sys_Log syslog)
        {
            syslog.Level = LogLevel.DEBUG.ToString();
            if (log.IsDebugEnabled)
            {
                log.Debug(syslog);
            }
        }

        /// <summary>
        /// 警告日志信息
        /// </summary>
        /// <param name="message"></param>
        public static void Warn(Sys_Log syslog)
        {
            syslog.Level = LogLevel.WARN.ToString();
            if (log.IsWarnEnabled)
            {
                log.Warn(syslog);
            }
        }

        /// <summary>
        /// 错误日志信息
        /// </summary>
        /// <param name="message"></param>
        public static void Error(Sys_Log syslog)
        {
            syslog.Level = LogLevel.ERROR.ToString();
            if (log.IsErrorEnabled)
            {
                log.Error(syslog);
            }
        }
        /// <summary>
        /// 毁灭性日志信息
        /// </summary>
        /// <param name="message"></param>
        public static void Fatal(Sys_Log syslog)
        {
            syslog.Level = LogLevel.FATAL.ToString();
            if (log.IsFatalEnabled)
            {
                log.Fatal(syslog);
            }
        }

    }
}
